#include "tcl_mstar_dtv_tv.h"

TCL_MSTAR_DTV_TV::TCL_MSTAR_DTV_TV()
{
}
TCL_MSTAR_DTV_TV::~TCL_MSTAR_DTV_TV()
{

}

int TCL_MSTAR_DTV_TV::Read_Data(QDataStream &in)
{
  in>>ui2_ch_val
      >>ps_name
        >>ui2_class
          >>ui2_type
          >>ui4_freq
          >>ui2_isfav
            >>ui2_isskip;
  return 1;
}

int TCL_MSTAR_DTV_TV::Write_Data(QDataStream &out)
{


    out<<ui2_ch_val
       <<ps_name
       <<ui2_class
         <<ui2_type
       <<ui4_freq
       <<ui2_isfav
      <<ui2_isskip;
  return 1;
}

void TCL_MSTAR_DTV_TV::Set_Data(int order,QVariant value)
{
    bool flag=false;
    bool *ok=&flag;
     switch(order)
     {
     case 1:
         ps_name=value.toString();
      break;
     case 0:
          ui2_ch_val=(ushort)value.toUInt(ok);
          STRING_TRAN_ERROR_0;
      break;
     case 2:
         if(0==strcmp("DTV-T",value.toString().toStdString().c_str()))
             ui2_class=0;
         else
             ui2_class=1;

      break;
     case 3:
         if(strcmp("D",value.toString().toStdString().c_str()))
             ui2_type=1;
         else if(strcmp("R",value.toString().toStdString().c_str()))
             ui2_type=2;
         else if(strcmp("T",value.toString().toStdString().c_str()))
             ui2_type=3;
         else if(strcmp("U",value.toString().toStdString().c_str()))
             ui2_type=4;
         else
             ui2_type=5;
         break;
     case 4:
         ui4_freq=(ushort)value.toUInt(ok);
         STRING_TRAN_ERROR_0;
         break;
     case 5:
          ui2_isfav=(ushort)value.toUInt(ok);
          STRING_TRAN_ERROR_0;
      break;
     case 6:
          ui2_isskip=(ushort)value.toUInt(ok);
          STRING_TRAN_ERROR_0;
      break;
     default:
         Q_ASSERT(order<NUM_DTV_ITEM&&order>0);
      //qDebug("In MSTAR DTV set_Data：order error\n");
     }
}


int TCL_MSTAR_DTV_TV::Count_Item() const
{
    return NUM_DTV_ITEM;
}

void TCL_MSTAR_DTV_TV::Get_Data(QList<QString> *ms_data)const
{
    QString tmp;
    tmp.setNum(ui2_ch_val);
    ms_data->append(tmp);
    ms_data->append(ps_name);
    if(ui2_class==0)
        tmp="DTV-B";
    else
        tmp="DTV-C";
    ms_data->append(tmp);
    switch(ui2_type)
    {
        case 1:
            tmp="D";
            break;
        case 2:
            tmp="R";
            break;
        case 3:
            tmp="T";
            break;
        default:
            tmp="U";
            break;
    }
    ms_data->append(tmp);
    tmp.setNum(ui4_freq);
    ms_data->append(tmp);
    tmp.setNum(ui2_isfav);
    ms_data->append(tmp);
    tmp.setNum(ui2_isskip);
    ms_data->append(tmp);
}

int TCL_MSTAR_DTV_TV::Set_Data(QList<QString>& ms_data)
{
    Q_ASSERT( ms_data.size()==NUM_DTV_ITEM);
    bool flag=false;
    bool *ok=&flag;
    ui2_ch_val=ms_data.at(0).toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ps_name=ms_data.at(1);
    ui2_class=ms_data.at(2).toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ui2_type=ms_data.at(3).toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ui4_freq=ms_data.at(4).toUInt(ok);
    STRING_TRAN_ERROR_1(-1);

    ui2_isfav=ms_data.at(5).toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
    ui2_isskip=ms_data.at(6).toUShort(ok);
    STRING_TRAN_ERROR_1(-1);
}

QString TCL_MSTAR_DTV_TV::Get_Item(int i)
{
    Q_ASSERT(i>=0&&i<NUM_DTV_ITEM);
    QString tmp;
    switch(i)
    {
        case 0:
            tmp.setNum(ui2_ch_val);
            break;
        case 1:
            tmp=ps_name;
            break;
        case 2:
            tmp.setNum(ui2_class);
            break;
        case 3:
        tmp.setNum(ui2_type);
                    break;
        case 4:
            tmp.setNum(ui4_freq);
            break;
        case 5:
            tmp.setNum(ui2_isfav);
            break;
        case 6:
            tmp.setNum(ui2_isskip);
            break;
        default:
            tmp=" ";
    }
    return tmp;
}
